#include "QtCardSelector.h"

QtCardSelector::QtCardSelector(QWidget *parent, Qt::WFlags flags): QWidget(parent, flags)
{
	ui.setupUi(this);

	ui.group2->SetColumnSize(5);
	ui.group2->SetSize(5);

	CardGroup CG;

	Card forwardcard;
	forwardcard.SetForward();
	
	Card backwardcard;
	backwardcard.SetBackward();

	Card turnleftcard;
	turnleftcard.SetLeftTurn();

	Card turnrightcard;
	turnrightcard.SetRightTurn();
	
	CG.AddCard(forwardcard);
	CG.AddCard(backwardcard);
	CG.AddCard(turnrightcard);
	CG.AddCard(turnleftcard);
	CG.AddCard(forwardcard);
	CG.AddCard(forwardcard);
	CG.AddCard(backwardcard);
	CG.AddCard(backwardcard);
	CG.AddCard(turnrightcard);

	ui.group1->SetCardGroup(CG);

	

	QObject::connect(ui.group1, SIGNAL(ClickedCard(QtCardGroup*, unsigned int)), this, SLOT(AddCard(QtCardGroup*, unsigned int)));
	QObject::connect(ui.group2, SIGNAL(ClickedCard(QtCardGroup*, unsigned int)), this, SLOT(RemoveCard(QtCardGroup*, unsigned int)));
}

QtCardSelector::~QtCardSelector()
{

}


void QtCardSelector::AddCard(QtCardGroup* group, unsigned int index)
{
	QtCard *card = group->GetCard(index);

	if (!ui.group2->Full() && card)
	{
		ui.group2->AddCard( card->GetCard() );
		group->RemoveCard(index);
	}
}

void QtCardSelector::RemoveCard(QtCardGroup* group, unsigned int index)
{
	QtCard *clickedCard = group->GetCard(index);

	if (clickedCard)
	{
		Card deletedCard = clickedCard->GetCard();

		ui.group2->RemoveCard(index);
		ui.group1->AddCard( deletedCard );
	}
}
